﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace SDT.Libraries.Utilities
{
    public class AdminUser
    {
        public static int UserId
        {
            get
            {
                if (HttpContext.Current.Session["AdminUserID"] != null)
                    return Convert.ToInt32(HttpContext.Current.Session["AdminUserID"]);
                else
                    return -1;
            }
            set
            {
                HttpContext.Current.Session["AdminUserID"] = value;
            }
        }

        public static Guid UserGuidId
        {
            get
            {
                if (HttpContext.Current.Session["AdminUserID"] != null)
                    return new Guid(HttpContext.Current.Session["AdminUserID"].ToString());
                else
                    return new Guid("");
            }
            set
            {
                HttpContext.Current.Session["AdminUserID"] = value;
            }
        }

        public static string UserName
        {
            get
            {
                if (HttpContext.Current.Session["AdminUserName"] != null)
                    return Convert.ToString(HttpContext.Current.Session["AdminUserName"]);
                else
                    return "";
            }
            set
            {
                HttpContext.Current.Session["AdminUserName"] = value;
            }
        }

        private static List<string> ListUrl
        {
            get
            {
                if (HttpContext.Current.Session["AdminPermitUrls"] != null)
                    return HttpContext.Current.Session["AdminPermitUrls"] as List<string>;
                else
                {
                    List<string> listUrl = new List<string>();
                    HttpContext.Current.Session["AdminPermitUrls"] = listUrl;
                    return listUrl;
                }
            }
        }

        public static bool checkPermitUrl(string url)
        {
            url = url.ToLower();
            foreach (string str in ListUrl)
            {
                if (url.Contains(str))
                    return true;
            }
            return false;
        }



        public static void logout()
        {
            HttpContext.Current.Session.Remove("SystemAdmin");
            HttpContext.Current.Session.Remove("AdminUserID");
            HttpContext.Current.Session.Remove("AdminUserName");
            HttpContext.Current.Session.Remove("AdminFullName");
            HttpContext.Current.Session.Remove("AdminPermitUrls");
            HttpContext.Current.Session.Remove("AdminRoles");
            HttpContext.Current.Session.Remove("AdminMenuItem");
        }
    }
}
